package com.taokatao.cardmee.common.widget;

import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;

import com.taokatao.cardmee.R;

import butterknife.BindView;

public class ProgressLineView extends LinearLayout {

    @BindView(R.id.v_part_completed) View vPartCompleted;
    @BindView(R.id.v_part_waiting) View vPartWaiting;

    private LinearLayout.LayoutParams completedLp;
    private LinearLayout.LayoutParams waitingLp;

    public ProgressLineView(Context context) {
        this(context, null);
    }

    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    public ProgressLineView(Context context, AttributeSet attrs) {
        super(context, attrs);

        setOrientation(HORIZONTAL);

        completedLp = new LayoutParams(0, LayoutParams.MATCH_PARENT);
        vPartCompleted = new View(context);
        vPartCompleted.setBackgroundResource(R.drawable.shape_progress_line);
        vPartCompleted.setLayoutParams(completedLp);
        addView(vPartCompleted);

        waitingLp = new LayoutParams(0, LayoutParams.MATCH_PARENT);
        vPartWaiting = new View(context);
        vPartWaiting.setLayoutParams(waitingLp);
        addView(vPartWaiting);

        updateProgress(0);
    }

    public void updateProgress(int progress) {
        if (progress < 0 || progress > 100) {
            return; // error progress
        }
        completedLp.weight = progress;
        waitingLp.weight = 100 - progress;
        requestLayout();
    }

}
